﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.WebControls;
using BLL;
using Model;
using ZedGraph;

public partial class StatisticData_TimeStatistic_TimeStatisticPID_StatisticYearPID : System.Web.UI.Page
{
    private string var_productTypeID
    {
        get { return ViewState["var_productTypeID"].ToString(); }
        set { ViewState["var_productTypeID"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindProductTypeID();
        }
    }

    private void BindProductTypeID()
    {
        ProductType pt = new ProductType();
        this.DropDownList1.DataSource = pt.LoadEntities();
        this.DropDownList1.DataTextField = "ProductTypeName";
        this.DropDownList1.DataValueField = "ProductTypeID";
        this.DropDownList1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        var_productTypeID = this.DropDownList1.SelectedValue;
        BindYear_QPID();
        this.ZedGraphWeb1.Visible = true;
    }

    private void BindYear_QPID()
    {
        Test_QT tq = new Test_QT();
        this.GridView1.DataSource = tq.GetYear_QPID(var_productTypeID);
        this.GridView1.DataBind();
    }


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindYear_QPID();
    }
    protected void ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
    {
        int i = 0;
        int j = 0;
        Test_QT t_qt = new Test_QT();
        List<Time_QInfo> t_qs = (List<Time_QInfo>)t_qt.GetYear_QPID(var_productTypeID);

        GraphPane myPane = pane[0];

        myPane.Title.Text = "按日历年统计产能情况";
        myPane.XAxis.Title.Text = "日历年";
        myPane.YAxis.Title.Text = "产能情况";

        //创建曲线
        PointPairList list = new PointPairList();
        foreach (Time_QInfo t_q in t_qs)
        {
            double y = (double)t_q.Quantity;
            int x = i;
            i++;
            list.Add(x, y);
        }
        //LineItem myCurve = myPane.AddCurve("", list, Color.Blue, SymbolType.Square);
        //myCurve.Line.IsSmooth = true;
        myPane.AddBar("合格腔体数", list, Color.Green);

        PointPairList list1 = new PointPairList();
        foreach (Time_QInfo t_q in t_qs)
        {
            double y = (double)t_q.Total;
            int x = i;
            i++;
            list1.Add(x, y);
        }
        myPane.AddBar("测试次数", list1, Color.Blue);

        string[] labels = new string[t_qs.Count];
        //给x轴上的每一个间隔点加上说明文字
        foreach (Time_QInfo t_q in t_qs)
        {
            labels[j] = t_q.DayTime;
            j++;
        }

        myPane.XAxis.Scale.TextLabels = labels; //这里设置的是TextLabels属性，所以下面x轴的类型必须也设置为Text   

        //设置x轴的样式
        myPane.XAxis.Type = AxisType.Text;
        MyGraphStyle.BuildbarGraphStyle(myPane);

        pane.AxisChange(g);
    }
}
